<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    <button>来个好玩的</button>
    <button>下去吧</button>
    <hr>

    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class Video extends React.Component {
            state = {
                src: 'http://api.xiaohigh.com:8090/video/random'
            }

            //1. 构造方法  props 是组件外向组件内出入的数据
            constructor(props){
                super(props);
                //如果不传入 props 的话, 则这个位置访问不到 props 属性
                console.log('1 - 组件挂载 - constructor 构造方法执行')
            }

            //3. 渲染
            render(){
                console.log('3-组件渲染 - render 执行');
                return <div className="container">
                        <button onClick={this.force}>强制更新</button><br /><br/>
                        <video width="300" autoPlay={true} controls src={this.state.src} onClick={this.change}></video>
                    </div>
            }

            //强哥更新
            force = () => {
                this.forceUpdate();
            }

            change = () => {
                this.setState({
                    src: 'http://api.xiaohigh.com:8090/video/random?t='+Date.now()
                })
            }

            //组件应该要更新了     更新开关
            shouldComponentUpdate(){
                console.log('1-组件应该要更新了');
                return true;
            }

            //组件将要更新
            componentWillUpdate(){
                console.log('2-组件将要更新');
            }

            //组件完成更新
            componentDidUpdate(){
                console.log('4-组件完成更新');
            }
            
        }

        let btns = document.querySelectorAll('button');

        btns[0].onclick = function(){
            ReactDOM.render(<Video />, document.querySelector("#root"));
        }

        btns[1].onclick = function(){
            ReactDOM.unmountComponentAtNode(document.querySelector('#root'));
        }

    </script>
</body>
</html>